1 module unde.games.dizzy.omega.save_load; 2 3 import std.algorithm; 4 import std.file; 5 import std.process; 6 import std.stdio; 7 8 string[string] load() 9 { 10 string[string] s; 11 version (Windows) 12 { 13 string home = environment["APPDATA"]; 14 } 15 else 16 { 17 string home = environment["HOME"]; 18 } 19 20 try 21 { 22 auto f = File(home ~ "/.dizzy_omega/save", "r"); 23 foreach (line; f.byLine()) 24 { 25 auto eq = find(line, "="); 26 if (eq) 27 { 28 string key = line[0..eq.ptr - line.ptr].idup(); 29 string str = eq[1..$].idup(); 30 s[key] = str; 31 } 32 } 33 f.close(); 34 } 35 catch (Exception e) 36 { 37 } 38 return s; 39 } 40 41 void save(ref string[string] s) 42 { 43 version (Windows) 44 { 45 string home = environment["APPDATA"]; 46 } 47 else 48 { 49 string home = environment["HOME"]; 50 } 51 mkdirRecurse(home ~ "/.dizzy_omega/"); 52 53 auto f = File(home ~ "/.dizzy_omega/save", "w"); 54 foreach(key, str; s) 55 { 56 f.writef("%s=%s\n", key, str); 57 } 58 f.close(); 59 }